<!--
 * @Author: 孙大大
 * @Date: 2022-04-12 20:36:55
 * @LastEditTime: 2022-04-12 22:39:47
 * @FilePath: \黑马面面\src\views\questions\randoms.vue
-->
<template>
  <div class="container">
    <el-card class="box-card">
      <el-form ref="form" :model="pageP" label-width="auto" size="small">
        <el-form-item label="关键字">
          <el-input placeholder="请输入内容" v-model="pageP.keyword"></el-input>
        </el-form-item>
        <el-button type="primary" plain @click="reset">清除</el-button>
        <el-button type="primary" @click="getCompanyInfo">搜索</el-button>
      </el-form>
      <el-alert :title="'共' + data.total + '条数据'" type="info" show-icon>
      </el-alert>
      <el-table :data="data.list" style="width: 100%">
        <el-table-column prop="bianhao" label="编号" width="150" align="center">
        </el-table-column>
        <el-table-column prop="tixing" label="题型" width="150" align="center">
        </el-table-column>
        <el-table-column prop="bianhao2" label="题目编号" align="center">
        </el-table-column>
        <el-table-column
          prop="time"
          label="录入时间"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="huida"
          label="答题时间"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="zhengque" label="正确率" align="center">
        </el-table-column>
        <el-table-column
          prop="people"
          label="录入人"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="address" label="操作" align="center">
          <template slot-scope="{ row }">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="medium"
              circle
              @click="del(row.index)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <br />
      <!-- 分页器 -->
      <div class="fenye">
        <el-pagination
          background
          :page-sizes="[10, 20, 30, 40]"
          layout="prev, pager, next,sizes,jumper"
          :total="data.total"
          :size="pageP.pageSize"
          :current-page="pageP.page"
          @current-change="changePage"
          @size-change="changeSize"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
// import { getZutiList } from "@/api/tiku";
export default {
  name: "zuti",
  components: {},
  props: {},
  data() {
    return {
      data: [],
      search: {
        state: "",
      },
      pageP: {
        page: 1,
        pageSize: 10,
        keyword: "",
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getCompanyInfo();
  },
  mounted() {},
  methods: {
    async del(id) {
      this.$confirm("确认删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const { data } = await this.$http.post("/del", id);
          console.log(data);
          if (this.data.list.length === 1 && this.pageP.page !== 1) {
            this.pageP.page--;
          }
          this.getCompanyInfo();

          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    reset() {
      // this.getCompanyInfo();
      this.pageP = {
        page: 1,
        pageSize: this.pageP.pageSize,
        keyword: "",
      };
      this.getCompanyInfo();
    },

    async getCompanyInfo() {
      const { data } = await this.$http.post("/tizu", this.pageP);
      // console.log(data);
      this.data = data.data;
    },
    //改变页码
    changePage(newPage) {
      this.pageP.page = newPage; // 将当前页码赋值给当前的最新页码
      this.getCompanyInfo();
    },
    changeSize(newPageSize) {
      this.pageP.pageSize = newPageSize;
      this.getCompanyInfo();
    },
    getInfoAgain() {},
  },
};
</script>
<style lang="scss" scoped>
.container {
  margin: 10px;
  .el-form {
    display: flex;
    flex-wrap: wrap;
    .el-button {
      height: 34px;
      line-height: 8px;
    }
    .el-form-item {
      width: 25%;
      padding: 0 10px;
      margin-bottom: 30px;
      .el-select {
        width: 100%;
      }
    }
  }
  .el-pagination {
    // float: right;
    padding-bottom: 30px;
  }
}
</style>
